package com.ywgt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ywgt.pojo.Collect;
import com.ywgt.mapper.CollectMapper;
import com.ywgt.service.CollectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 收藏表 服务实现类
 * </p>
 *
 * @author yiping
 * @since 2021-03-13
 */
@Service
public class CollectServiceImpl extends ServiceImpl<CollectMapper, Collect> implements CollectService {

    @Override
    public Page<Collect> getCollects(Integer userId, Integer valueId, int page, int limit, String sort, String order) {
        PageHelper.startPage(page,limit);
        return baseMapper.selectCollects(userId,valueId,sort,order);
    }

    @Override
    public int counts(Integer userId, Integer id) {
        LambdaQueryWrapper<Collect> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Collect::getUserId,userId);
        wrapper.eq(Collect::getValueId,id);
        List<Collect> collects = baseMapper.selectList(wrapper);
        return collects==null?0:collects.size();
    }
}
